package cn.janyd.jmall.userweb.controller.passport;

import cn.janyd.common.core.vo.CommonResult;
import cn.janyd.jmall.userweb.controller.passport.vo.AccessTokenRespVo;
import cn.janyd.jmall.userweb.controller.passport.vo.PassportLoginBySmsReqVo;
import cn.janyd.jmall.userweb.manager.passport.PassportManager;
import cn.janyd.jmall.web.core.util.WebUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import static cn.janyd.common.core.vo.CommonResult.success;

/**
 * @author janyd
 * @since 2020/8/10 17:58
 */
@Api(tags = "用户 Passport API")
@RestController
@RequestMapping("/passport")
public class UserPassportController {

    private final PassportManager passportManager;

    public UserPassportController(PassportManager passportManager) {
        this.passportManager = passportManager;
    }

    @ApiOperation("手机验证码登录")
    @PostMapping("/login-by-sms")
    public CommonResult<AccessTokenRespVo> loginBySms(@RequestBody @Valid PassportLoginBySmsReqVo loginBySmsReqDTO,
                                                      HttpServletRequest request) {
        return success(passportManager.loginBySms(loginBySmsReqDTO, WebUtil.getIp(request)));
    }
}
